$().ready(function() {
	validateRule();
	
	$(function () {
        $("#payDate").datepicker({
            language: "zh-CN",
            autoclose: true,//选中之后自动隐藏日期选择框
            clearBtn: false,//清除按钮
            todayBtn: false,//今日按钮
            format: "yyyy-mm-dd"//日期格式，详见 http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format
        });
    });
	
	// 期数点击事件
	$('#beAnnual').on('change', function() {
		var beAnnual = $('#beAnnual').val();
		if("other" == beAnnual){
			$("#annualDiv").attr("style", "display:none");
			$("#otherDiv").attr("style", "display:inline");
		}else{
			$("#annualDiv").attr("style", "display:inline");
			$("#otherDiv").attr("style", "display:none");
		}
	});
	
	$("#servZjwhFee").bind("change input propertychange", function() {
		annualFeeChange();
	});
	$("#servRkqjbrFee").bind("change input propertychange", function() {
		annualFeeChange();
	});
	$("#servDzsbFee").bind("change input propertychange", function() {
		annualFeeChange();
	});
	$("#servZzsbFee").bind("change input propertychange", function() {
		annualFeeChange();
	});
	$("#servDlfpFee").bind("change input propertychange", function() {
		annualFeeChange();
	});
	$("#servDdyfpFee").bind("change input propertychange", function() {
		annualFeeChange();
	});
	$("#servLsjzFee").bind("change input propertychange", function() {
		annualFeeChange();
	});
});


function annualFeeChange(){
	var servZjwhFee = $("#servZjwhFee").val();
	var servRkqjbrFee = $("#servRkqjbrFee").val();
	var servDzsbFee = $("#servDzsbFee").val();
	var servZzsbFee = $("#servZzsbFee").val();
	var servDlfpFee = $("#servDlfpFee").val();
	var servDdyfpFee = $("#servDdyfpFee").val();
	var servLsjzFee = $("#servLsjzFee").val();
	
	var total = 0;
	if (typeof servZjwhFee != 'undefined' && servZjwhFee != '')
		total = parseFloat(servZjwhFee)+total;
	if (typeof servRkqjbrFee != 'undefined' && servRkqjbrFee !='')
		total = parseFloat(servRkqjbrFee)+total;
	if (typeof servDzsbFee != 'undefined' && servDzsbFee !='')
		total = parseFloat(servDzsbFee)+total;
	if (typeof servZzsbFee != 'undefined' && servZzsbFee!='')
		total = parseFloat(servZzsbFee)+total;
	if (typeof servDlfpFee != 'undefined' && servDlfpFee !='')
		total = parseFloat(servDlfpFee)+total;
	if (typeof servDdyfpFee != 'undefined' && servDdyfpFee!='')
		total = parseFloat(servDdyfpFee)+total;
	if (typeof servLsjzFee != 'undefined' && servLsjzFee!='')
		total = parseFloat(servLsjzFee)+total;
	
	 $("#annualFee").val(total);
}

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/system/bizCustomer/saveXufei",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			payDate : {
				required : true
			}
		},
		messages : {
			payDate : {
				required : icon + "请输入采集时间"
			}
		}
	})
}